/*
 * @(#)AssociationTypeOrderComparator.java
 * Date 2013-09-12
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.registry.transformer.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;

import oasis.names.tc.ebxml_regrep.xsd.rim._3.AssociationType1;


/**
 * Class description
 *
 *
 * @version        v1.0, 2013-09-12
 * @author         Jim Horner
 */
public class AssociationTypeOrderComparator implements Comparator<AssociationType1> {

    /** Field description */
    private final List<String> ids;

    /**
     * Constructs ...
     *
     */
    private AssociationTypeOrderComparator() {

        super();
        this.ids = new ArrayList<>();

    }

    /**
     * Constructs ...
     *
     *
     * @param ids
     */
    public AssociationTypeOrderComparator(Collection<String> ids) {

        this();
        this.ids.addAll(ids);
    }

    /**
     * Constructs ...
     *
     *
     * @param ids
     */
    public AssociationTypeOrderComparator(String[] ids) {

        this();
        this.ids.addAll(Arrays.asList(ids));
    }

    /**
     * Method description
     *
     *
     * @param o1
     * @param o2
     *
     * @return
     */
    @Override
    public int compare(AssociationType1 o1, AssociationType1 o2) {

        int result = 0;

        boolean o1contains = this.ids.contains(o1.getTargetObject());
        boolean o2contains = this.ids.contains(o2.getTargetObject());

        if (o1contains && (o2contains == false)) {

            result = 1;

        } else if (o2contains && (o1contains == false)) {

            result = -1;
        }

        return result;
    }
}
